package com.wwy.monitor.config;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

/**
 * Title: MyBatisMapperScannerConfig
 */
@Configuration
@AutoConfigureAfter(MyBatisConfig.class)
public class MyBatisMapperScannerConfig {

    static Set<String> mappers = new HashSet<String>();

    static{
        mappers.add("com.wwy.monitor.mapper.tddl");
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        String basePackages = mappers.stream().reduce((s1,s2) -> s1 + "," + s2).get();
        mapperScannerConfigurer.setBasePackage(basePackages);
        Properties properties = new Properties();
        properties.setProperty("mappers", "com.wwy.monitor.config.MyMapper");
        properties.setProperty("notEmpty", "false");
        properties.setProperty("IDENTITY", "MYSQL");
        mapperScannerConfigurer.setProperties(properties);
        return mapperScannerConfigurer;

    }
}
